//
//  XYStatus.swift
//  WeiboSourceCode
//
//  Created by 周星宇 on 15/12/31.
//  Copyright © 2015年 cn.weibo. All rights reserved.
//

import UIKit

class XYStatus: NSObject {
    
    
    // MARK: 模型数据
    // 当前微博的 Id
    var id: Int64 = 0
    /// 微博的内容
    var text: String?
    /// 微博的创建时间
    var created_at: String?
    /// 微博的来源
    var source: String?
    /// 当前微博的作者信息
    var user: XYUser?
    /// 转发微博的字段
    var retweeted_status: XYStatus?
    // 转发评论赞的数量
    var reposts_count: Int = 0
    var comments_count: Int = 0
    var attitudes_count: Int = 0
    // 配图
    var pic_urls: [XYHomePicture]?
    
    
    // 解析模型嵌套 (kvc 内部会调用这个方法)
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = XYUser(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = XYStatus(dict: dict)
            }
        }else if key == "pic_urls" {
            
            if let dicts = value as? [[String: AnyObject]] {
                var tempArray = [XYHomePicture]()
                for dict in dicts {
                    let homePicture = XYHomePicture(dict: dict)
                    tempArray.append(homePicture)
                }
                pic_urls = tempArray
            }
        }else{
            
            super.setValue(value, forKey: key)
        }
    }
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
        
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    
}
